package com.corechina.apex_osswords.controller;


import com.corechina.apex_osswords.common.Response;
import com.corechina.apex_osswords.common.WeiXinUserUtils;
import com.corechina.apex_osswords.domain.dto.CoreEquipmentCheckResultDto;
import com.corechina.apex_osswords.service.ICoreEquipmentCheckResultService;
import com.corechina.apex_osswords.service.ICoreEquipmentCheckService;
import com.corechina.apex_osswords.service.ICorePollingEquipmentService;
import com.corechina.apex_osswords.service.ICorePollingPlanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 巡检相关--微信 前端控制器
 * </p>
 *
 * @author cc
 * @since 2023-03-10
 */

@Api(tags = "巡检相关--微信")
@RestController
@RequestMapping("/core/weiXinPolling")
public class CoreWeiXinPollingController {

    @Autowired
    private ICorePollingPlanService iCorePollingPlanService;

    @Autowired
    private ICorePollingEquipmentService iCorePollingEquipmentService;

    @Autowired
    private ICoreEquipmentCheckResultService iCoreEquipmentCheckResultService;

    @Autowired
    private ICoreEquipmentCheckService iCoreEquipmentCheckService;

    @ApiOperation("巡检计划列表")
    @GetMapping("/getPollingPlanList")
    public Response getPollingPlanList(Integer pollingId, Integer status, Integer isToday, String beginDate, String endDate, Integer pageIndex, Integer pageSize) {
        return iCorePollingPlanService.getList(null, pollingId, WeiXinUserUtils.getEnterpriseId(), status, null, WeiXinUserUtils.getUserId(), isToday, beginDate, endDate, pageIndex, pageSize);
    }

    @ApiOperation("巡检计划详情")
    @GetMapping("/getPollingPlanDetails")
    public Response getPollingPlanDetails(Integer id) {
        return iCorePollingPlanService.getOne(id);
    }

    @ApiOperation("巡检设备列表")
    @GetMapping("/getPollingEquipmentList")
    public Response getPollingEquipmentList(Integer planId, Integer status, Integer type, Integer pageIndex, Integer pageSize) {
        return iCorePollingEquipmentService.getList(planId, null, status, type, pageIndex, pageSize);
    }

    @ApiOperation("巡检设备详情")
    @GetMapping("/getPollingEquipmentDetails")
    public Response getPollingEquipmentDetails(Integer id) {
        return iCorePollingEquipmentService.getOne(id);
    }

    @ApiOperation("增加设备巡检结果")
    @PostMapping("/addCheckResult")
    public Response addCheckResult(@RequestBody CoreEquipmentCheckResultDto coreEquipmentCheckResultDto) {
        return iCoreEquipmentCheckResultService.add(coreEquipmentCheckResultDto);
    }

    @ApiOperation("根据计划id和设备编码获取设备详情")
    @GetMapping("/getPollingEquipmentBySerialNumber")
    public Response getPollingEquipmentBySerialNumber(String serialNumber, Integer planId) {
        return iCorePollingEquipmentService.getPollingEquipmentBySerialNumber(serialNumber, planId);
    }

    @ApiOperation("根据设备类型获取检查项列表")
    @GetMapping("/getEquipmentCheckList")
    public Response getCheckList(Integer equipmentType) {
        return iCoreEquipmentCheckService.getList(equipmentType, null, WeiXinUserUtils.getEnterpriseId());
    }

    @ApiOperation("根据项目id查询巡检计划")
    @GetMapping("/getListByProjectIdForWeiXin")
    public Response getListByProjectIdForWeiXin(String beginDate, String endDate, Integer projectId, Integer status, Integer pageIndex, Integer pageSize) {
        return iCorePollingPlanService.getListByProjectIdForWeiXin(beginDate, endDate, projectId, status, WeiXinUserUtils.getEnterpriseId(), pageIndex, pageSize);
    }
}

